package com.kwok.rbac.application.common.utils;

import java.util.HashMap;

/**
 * 统一返回R对象
 */
public class R extends HashMap {

    public static R success(){
        R success = new R();
        success.put("code",200);
        return success;
    }

    public static R success(Object data){
        R success = success();
        success.put("data",data);
        return success;
    }

    public static R failure(){
        R failure = new R();
        failure.put("code",500);
        return failure;
    }

    public static R failure(String message){
        R failure = failure();
        failure.put("message",message);
        return failure;
    }

    public static R failure(Integer code,String message){
        R failure = failure();
        failure.put("code",code);
        failure.put("message",message);
        return failure;
    }

    public static R write(Boolean b){
        if (b){
            return R.success();
        }
        return R.failure("CUD写操作失败");
    }

}
